package com.fyfeng.yuzw.emoji;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Html;
import android.text.Spanned;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity implements OnSendClickListener {

    private static final String tag = MainActivity.class.getSimpleName();

    public KJEmojiFragment emojiFragment = new KJEmojiFragment();

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.emoji_keyboard, emojiFragment).commit();
        emojiFragment.setOnSendClickListener(this);

        textView = (TextView)findViewById(R.id.text);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClickSendButton(Editable str) {

        Log.d(tag, "str = " + str.toString());
        Spanned span = Html.fromHtml(str.toString());
        span = InputHelper.displayEmoji(getResources(), span);
        textView.setText(span);
    }

    @Override
    public void onClickFlagButton() {

    }
}
